package com.linln.config.scheduling;

import com.linln.modules.system.domain.Param;
import com.linln.modules.system.repository.ParamRepository;
import com.linln.modules.system.repository.UvRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
public class SaticScheduleTask {
    @Autowired
    UvRepository uvRepository;
    @Autowired
    ParamRepository paramRepository;
    //3.添加定时任务
    @Scheduled(cron = "0 30 0 * * ?")
    //或直接指定时间间隔，例如：5秒
    //@Scheduled(fixedRate=5000)
    private void configureTasks() {
         Param param =paramRepository.findFirstByName("visitor_counts");
        int newCount= uvRepository.findCountBefore();
        param.setValue(String.valueOf(Integer.valueOf(param.getValue())+newCount));
        paramRepository.save(param);
    }
}